$(function() {
	var zdata;
	var shopData = {
		data: [
			{
				"premises_name":"华新新城",					//小区名
				"building_num":"03",						//楼号
				"unit":"03",								//单元
				"room_num":"303",							//房间号		
				"time":"2017-09-03",						//报修时间
				"status":"未派单",							//维修状态
				"service_content":"水管炸裂",					//报修内容
				"total_price":"200",						//维修费用
				"score":"",									//评价得分(5个星星)
				"evaluation":""								//评价内容
				
			},
			{
				"premises_name":"泰安市奥林匹克花园小区",			//小区名
				"building_num":"01",						//楼号
				"unit":"01",								//单元
				"room_num":"101",							//房间号		
				"time":"2017-09-01",						//报修时间
				"status":"已完成",							//维修状态
				"service_content":"煤气泄漏",					//报修内容
				"total_price":"100",						//维修费用
				"score":"",									//评价得分(5个星星)
				"evaluation":""								//评价内容
				
			},
			{
				"premises_name":"华新世纪城",					//小区名
				"building_num":"02",						//楼号
				"unit":"02",								//单元
				"room_num":"202",							//房间号		
				"time":"2017-09-04",						//报修时间
				"status":"已评价",							//维修状态
				"service_content":"厕所堵塞",					//报修内容
				"total_price":"300",						//维修费用
				"score":"1",								//评价得分(5个星星)
				"evaluation":"漫天要价，还没修好，mdzz,吃我一记成年老肥腿。古娜拉黑暗之神，拔了个鸡，沉！巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉我就凑个字数测试测试"			//评价内容
			},
		]
	};
	function shopModal() {
		var self = this;
		self.defaults = {
			activeIndex: 0,
			isAdd: false,
			isAllcheck: false,
			isCancle: true,
			initData: {
				"premises_name":"华新XXX",					//小区名
				"building_num":"00",						//楼号
				"unit":"00",								//单元
				"room_num":"000",							//房间号		
				"time":"2000-00-00",						//报修时间
				"status":"未派单",							//维修状态
				"service_content":"床板压断",					//报修内容
				"total_price":"0",						    //维修费用
				"score":"",									//评价得分(5个星星)
				"evaluation":""								//评价内容
			}
		}
		self.listData = ko.observableArray(shopData.data);
		self.line = ko.observable(self.defaults.initData);
		self.lineClick = function(data, e) {
			var lineData = $.extend({}, self.defaults.initData, data);
			self.line(lineData);
			var index = $(e.target).closest("li").index();
			self.defaults.activeIndex = index;
			self.defaults.isAdd = false;
			isHavePayButton(data);
		}
	}
	ko.applyBindings(new shopModal());
	//验证可否进行支付
	$('#submit').click(function(){
		//评价得分不能为空
		var score = check;
		console.log('score========>>'+score);
		if(!score){
			UM.alert({
			    title: '评价得分不能为空',
			    btnText: ["", "确定"],
			});
			return;
		}
		alert('可以进行评价');
		//to do 提交物业费的缴纳
	});
	//$('#testclick').click(function(){
	//	console.log(getWidthOfStar(5));
	//});
});
//如果客户的缴费状态为未缴费和无需缴纳，则将这张单据中的提交缴费按钮hidden掉，否则则取消hidden
function isHavePayButton(data) {
	check = '';
	var sta = data.status;
	var star_submit =   '<div style="float:left">'
							+'<a href="javascript:click(1)"><img src="img/star.png" id="star1" onMouseOver="over(1)" onMouseOut="out(1)"/></a>'
							+'<a href="javascript:click(2)"><img src="img/star.png" id="star2" onMouseOver="over(2)" onMouseOut="out(2)"/></a>'
							+'<a href="javascript:click(3)"><img src="img/star.png" id="star3" onMouseOver="over(3)" onMouseOut="out(3)"/></a>'
							+'<a href="javascript:click(4)"><img src="img/star.png" id="star4" onMouseOver="over(4)" onMouseOut="out(4)"/></a>'
							+'<a href="javascript:click(5)"><img src="img/star.png" id="star5" onMouseOver="over(5)" onMouseOut="out(5)"/></a>'
							+'<span id="message"></span>'
						+'</div>';
	var star_show = 	'<div id="bg">'
							+'<div id="over" style="width:'+getWidthOfStar(data.score)+'"></div>'
						+'</div>';
	//根据单据的状态，决定是否有提交按钮
	//根据单据状态，决定评价得分和评价内容是否显示，如果是已完成，显示评分提交的星星，能点击评价，如果是已评价，显示评分显示的星星。否则关掉隐藏星星页面和评价页面
	if(sta == '已完成'){
		console.log('<=======已完成=======>');
		$('#submit').show();
		$('#score_container').show();
		$('#evaluation_container').show();
		$('#score_pack').html(star_submit);
	}else if(sta == '已评价'){
		console.log('<=======已评价=======>');
		$('#submit').hide();
		$('#score_container').show();
		$('#evaluation_container').show();
		$('#score_pack').html(star_show);
	}else{
		console.log('<=======其他=======>');
		$('#submit').hide();
		$('#score_container').hide();
		$('#evaluation_container').hide();
		$('#score_pack').html('');
	}
}
//根据分数确定星星的width
function getWidthOfStar(starnumber){
	var starwidth = starnumber * 12;
	starwidth = starwidth + 'px';
	return starwidth;
}
